package com.huang;

import org.junit.jupiter.api.Test;

import java.io.*;

import static org.junit.jupiter.api.Assertions.*;

/**
 * @author HuangShen
 * @Description Junit5 测试
 * @create 2021-03-25 13:01
 */
class OperationTest {

    @Test
    public void test1() throws IOException {

        File file = new File("E:\\后端代码\\JavaSE\\hello.txt");
        FileInputStream fileInputStream = new FileInputStream(file);
        int read = fileInputStream.read();
        while (read!=-1){
            System.out.print((char) read);
            read=fileInputStream.read();
        }
        fileInputStream.close();


        FileOutputStream fileOutputStream = new FileOutputStream(file);
        String write="123214";
        fileOutputStream.write(write.getBytes());
        fileOutputStream.close();


    }



    @Test
    public void testFileReader1() throws IOException {
        File file = new File("E:\\后端代码\\JavaSE\\Day5\\src\\com\\huang\\hello.txt");
        FileReader fileReader = new FileReader(file);
        char[] chars = new  char[5];
        int read = fileReader.read(chars);

    }

    @Test
    public void testBufferStream() throws IOException {

        FileInputStream fileInputStream = new FileInputStream(new File("E:\\后端代码\\JavaSE\\Day5\\src\\com\\huang\\hello.txt"));
        FileOutputStream fileOutputStream = new FileOutputStream(new File("E:\\后端代码\\JavaSE\\Day5\\src\\com\\huang\\hello1.txt"));
        BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
        BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
        byte[] bytes = new byte[1024];
        int len;
        while ((len=bufferedInputStream.read(bytes))!=-1){
            bufferedOutputStream.write(bytes,0,len);
        }

        bufferedInputStream.close();
        bufferedOutputStream.close();
    }


}